﻿using Autofac;
using Domain.Events;
using Infrastructure.Events;
using System;
using System.IO;
using System.Reflection;

namespace GitSyncApp
{
    public static class ConfigureDomainServices
    {
        public static App AddDomainServices(this App app, ContainerBuilder builder)
        {
            // Domain Service
            builder.RegisterAssemblyTypes(Assembly.LoadFile(Path.Combine(Environment.CurrentDirectory, "Domain.Services.dll")))
                .AsImplementedInterfaces()
                .InstancePerDependency();

            // Domain Event
            builder.RegisterType<DomainEvent>()
                .As<IntegrationEvent>()
                .InstancePerDependency();

            builder.RegisterType<DomainEventHandler>()
                .As<IIntegrationEventHandler<DomainEvent>>()
                .InstancePerDependency();

            return app;
        }
    }
}
